<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
  let asyncCatch = ( promise)=>{
        return promise.then( res =>{
          return {res, err:null}
        })
        .catch( (err)=> {
            return {
                res:null,
                err,
            }
        })
    }

   //实现红绿灯 3秒打印红灯 2秒打印绿灯 1秒打印黄灯
    
   let setColor = function(color,delay){
      return new Promise(( resolve) =>{
         setTimeout( () => {
          console.log(color);
          resolve()
         },delay)
      } )
   }
   
   async function sett(){
      await asyncCatch(setColor("red",3000));
      await asyncCatch(setColor("green",2000));
      await asyncCatch(setColor("yellow",1000))
      await asyncCatch(sett())
   }
   sett()
</script>
</html>